/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSky.matcher;

import org.hamcrest.CustomMatcher;
import org.hamcrest.Matcher;
import ru.jSky.producer.Producer;

/**
 *
 * @author Rakev
 */
public class MatcherAdapter<F,T> extends CustomMatcher<T> {
    
    private Matcher<F> formMatcher;
    private Producer<T,F> producer;

    public MatcherAdapter(Producer<T,F> producer, Matcher<F> formMatcher) {
        super(formMatcher.toString());
        this.formMatcher = formMatcher;
        this.producer = producer;
    }

    @Override
    public boolean matches(Object item) {
        F producedValue = producer.produce((T) item);
        return formMatcher.matches(producedValue);
    }
    
}
